﻿using System;
using System.Diagnostics;

namespace OverStore.Runtime.ObjectRepository.Depot.IdentifierGenerator
{
    /// <summary>
    /// Generates new global unique identifiers.
    /// </summary>
    /// <typeparam name="TInstance">The type of the instance.</typeparam>
    public sealed class GuidGenerator<TInstance> : IIdentifierGenerator<TInstance, Guid>
        where TInstance : class
    {
        /// <summary>
        /// Obtain next identifier for specified instance.
        /// </summary>
        /// <param name="instance">The instance to obtain identifier for it.</param>
        /// <returns>
        /// The next result of identifier for specified instance.
        /// </returns>
        /// <exception cref="T:OverStore.Runtime.Repository.Depot.DepotException">The error occured due generating identifier.</exception>
        public Guid NextIdentifier(TInstance instance)
        {
            Debug.Assert(instance != null, "Generate identifier for null instance.");
            return Guid.NewGuid();
        }
    }
}
